﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using igflow.Components;

namespace igflow
{
    public static class CameraManager
    {
        static Camera DebugCamera;
        static Camera mainCamera;
        static Camera GUICamera;
        static Camera GUICamera3D;

        static List<GameObject.igGameObject> Mounts;
        public static void Init()
        {

            mainCamera = new Camera(60.0f, (float)Game1.screenWidth / (float)Game1.screenHeight, 0.1f, 500.0f , false);
            mainCamera.SetTarget(new Vector3(0, 0, 0));
            mainCamera.Position = new Vector3(-2.0f, 0, -10.0f);
            World.AddGameObject(mainCamera);

            //GUICamera = new Camera(60.0f, (float)Game1.screenWidth / (float)Game1.screenHeight, 0.1f, 500.0f, true);
            //World.AddGameObject(GUICamera);

            //GUICamera3D = new Camera(60.0f, (float)Game1.screenWidth / (float)Game1.screenHeight, 0.1f, 500.0f, false);
            //World.AddGameObject(GUICamera3D);

            World.AddGameObject(new igflow.Components.igCameraMount(new Vector3(-2.0f, 0, 0.05f) - new Vector3(0, 0, -10), new Vector3(-2.0f, 0, 0.05f)));
            World.AddGameObject(new igflow.Components.igCameraMount(new Vector3(0.0f, 0, 0.05f) - new Vector3(0, 0, -10), new Vector3(0.0f, 0, 0.05f)));
            World.AddGameObject(new igflow.Components.igCameraMount(new Vector3(2.0f, 0, 0.05f) - new Vector3(0, 0, -10), new Vector3(2.0f, 0, 0.05f)));
            World.AddGameObject(new igflow.Components.igCameraMount(new Vector3(4.0f, 0, 0.05f) - new Vector3(0, 0, -10), new Vector3(4.0f, 0, 0.05f)));

            Mounts = World.FindObjects(typeof(igCameraMount));
        }

        
        public static void AddMount(igflow.Components.igCameraMount target)
        {
            Mounts.Add(target);
        }

        public static Camera MainCamera
        {
            get
            {
             return mainCamera;
            }
        }

        public static Camera CurrentCamera
        {
            get
            {
                return mainCamera;
            }
        }

        static int currentMount = 0;

        internal static igCameraMount CurrentMount
        {
            get
            {
                return (igCameraMount)Mounts[currentMount];
            }
        }
        internal static void NextMount()
        {
            // Does nothing if we are at the end of the list
            int newMount = currentMount + 1;
            if (newMount < Mounts.Count)
            {
                currentMount = newMount;
                mainCamera.SetPosition(CurrentMount.Position);
                mainCamera.SetTarget(CurrentMount.TargetPosition);
            }
        }

        internal static void PreviousMount()
        {
            int newMount = currentMount - 1;
            if (newMount >= 0)
            {
                currentMount = newMount;
                mainCamera.SetPosition(CurrentMount.Position);
                mainCamera.SetTarget(CurrentMount.TargetPosition);
            }
        }
    }
}
